// lottery/pages/prize/prize.js
var common = require("../../../common/common.js").common;

var app = getApp();

Page({
    /**
   * 页面的初始数据
   */
    data: {
        domain: "",
        list: [],
        page: 1,
        lottery_id: ""
    },
    /**
   * 生命周期函数--监听页面加载
   */
    onLoad(options) {
        this.setData({
            domain: app.globalData.domain.slice(0, -10)
        });
        if (options.id) {
            this.setData({
                lottery_id: options.id
            });
        }
        this.getList();
    },
    /**
   * 生命周期函数--监听页面初次渲染完成
   */
    onReady() {},
    /**
   * 生命周期函数--监听页面显示
   */
    onShow() {},
    /**
   * 生命周期函数--监听页面隐藏
   */
    onHide() {},
    /**
   * 生命周期函数--监听页面卸载
   */
    onUnload() {},
    /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
    onPullDownRefresh() {
        this.setData({
            page: 1,
            list: []
        });
        this.getList();
        wx.stopPullDownRefresh();
    },
    /**
   * 页面上拉触底事件的处理函数
   */
    onReachBottom() {},
    /**
   * 用户点击右上角分享
   */
    onShareAppMessage() {},
    getList: function() {
        var that = this;
        common.request({
            endpoint: "Lottery/manage/my-prize-list",
            method: "post",
            data: {
                page: that.data.page,
                lottery_id: this.data.lottery_id
            },
            header: {
                "content-type": "application/json"
            },
            success: res => {
                var list = res.extra;
                if (list.length > 0) {
                    list = that.data.page == 1 ? list : that.data.list.concat(list);
                    that.setData({
                        list: list,
                        page: that.data.page + 1
                    });
                }
            }
        });
    },
    toOrder(e) {
        let id = e.currentTarget.dataset.id;
        wx.navigateTo({
            url: "/newPlace_order/pages/newPlace_order/newPlace_order?lottery_prize_id=" + id
        });
    }
});